package com.example.fw;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class ApplicationManager {

	public  WebDriver driver;
	public  String baseUrl;
	
	private NavigationiHelper naviHelp;
	private GroupHelper groupHelp;
	private ContactHelper contHelp;
	private MainHelper mainHelp;
	private Properties properties;
	
	public ApplicationManager(Properties properties){
		this.properties = properties;
		String browser = properties.getProperty("browser");
		if("firefox".equals(browser)){
			driver = new FirefoxDriver();
		}else if("ie".equals(browser)){			
		    System.setProperty("webdriver.ie.driver", "C:\\testautomation\\utils\\IEDriverServer.exe");
			driver = new InternetExplorerDriver();
		/*}else if("chrome".endsWith(browser)){
			driver = new ChromeDriver();*/
		}else {
			throw new Error("You are using usupported browser in properties file");
		}		
		baseUrl = properties.getProperty("baseUrl");
		//driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
		driver.get(baseUrl);	
	}
	
	public NavigationiHelper getNaviHelper(){
		if (naviHelp == null) {
			naviHelp = new NavigationiHelper(this);
		}
		return naviHelp;
	}
	
	public GroupHelper getGroupHelper(){
		if (groupHelp == null) {
			groupHelp = new GroupHelper(this);
		}
		return groupHelp;
	}
	
	public ContactHelper getContactHelper(){
		if (contHelp == null) {
			contHelp = new ContactHelper(this);
		}
		return contHelp;
	}
	
	public void stop() {
		driver.quit();	
	}
}
